#include "xmpppresencetask.h"
#include "XmlNode.h"
#include "constants.h"

namespace tinkle {

XmppPresenceTask::XmppPresenceTask(BaseTask *parent)
    : XmppTask(parent) {

}

XmppPresenceTask::~XmppPresenceTask() {

}

void XmppPresenceTask::SetState(SHOW_STATE state) {
    XmlNode *newNode = new XmlNode(STR_PRESENCE);
    ElementPtr element = newNode->GetElement()->AddChild(STR_SHOW);
    switch (state) {
        case ONLINE:
            break;
        case OFFLINE:
            (*newNode)()->SetAttrValue(STR_TYPE, "unavailable");
            break;
        case AWAY:
            element->SetContent("away");
            break;
        case CHAT:
            element->SetContent("chat");
            break;
        case DND:
            element->SetContent("dnd");
            break;
        case XA:
            element->SetContent("xa");
            break;
    }
    SendStanza(newNode);
}

void XmppPresenceTask::SetStatus(const std::string &status) {
    XmlNode *newNode = new XmlNode(STR_PRESENCE);
    ElementPtr element = newNode->GetElement()->AddChild(STR_STATUS);
    element->SetContent(status);
    SendStanza(newNode);
}

bool XmppPresenceTask::NextStanza(XmlNode *stanza) {
    if ((*stanza)()->GetName() == STR_PRESENCE) {
        printf ("haha, I'm received\n");
        return true;
    }
    return false;
}

}